<?php

namespace App\Api\Traits;

use Symfony\Component\HttpFoundation\Response;
/**
 * Trait RestfulRespon
 * 定义基于 Restful 风格的 Json 数据返回方法
 * @package App\Api\Traits
 */
trait RestfulResponse
{
    /**
     * success
     * @param array $data
     * @param array $header
     * @return \Illuminate\Http\JsonResponse
     */
    protected function success($data = [], $message = '数据请求成功。')
    {
        return response()->json([
            'code'    => 200,
            'message' => $message,
            'data'    => $data,
        ], 200);
    }

    protected function error($message = '请求无法处理。', $code = Response::HTTP_UNPROCESSABLE_ENTITY, $data = [])
    {
        return response()->json([
            'code'    => $code,
            'message' => $message,
            'data'    => $data,
        ], 200);
    }
}
